<!--
 * @Author: your name
 * @Date: 2020-06-01 11:20:54
 * @LastEditTime: 2020-06-01 12:46:05
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \museweb\src\views\musePage\rule\changeRule.vue
--> 
<template>
  <d2-container>
    <el-form ref="detailForm" :model="detailForm" label-width="140px">
      <el-form-item label="积分规则">
        <simpleRich v-model="detailForm.detail"></simpleRich>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('detailForm')">确定</el-button>
        <el-button @click="fnDeleteRules">删除</el-button>
      </el-form-item>
    </el-form>
  </d2-container>
</template>

<script>
import simpleRich from "@/components/muse/simple-rich/simple-rich";
import { changeRules, deleteRules, getRules } from '@/api/admin'
export default {
  name: "changeRule",
  components: { simpleRich },
  data() {
    return {
      detailForm: {}
    };
  },
  created() {
      this.getRules()
  },
  methods: {
    async submitForm(formName) {
      await changeRules(this.detailForm).then((res) => {
          this.$message({
                message: '添加规则成功',
                type: 'success'
            });
          this.getRules()
      })
    },

    async fnDeleteRules() {
      const { code } = await deleteRules({id: this.detailForm._id})
      if(code === 200) {
           this.$message({
                message: '删除成功',
                type: 'success'
            });
            this.getRules()
      }
    },

    async getRules() {
      const res = await getRules()
      if(res.code === 200) {
          this.detailForm = res.data || { detail: ''}
      }
    }
  }
};
</script>

<style scoped>
</style>
